<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>销售综合报表,航空公司版</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
    <body>
        <div id='report_airways_form_div'>
        </div>
        <script>
            Ext.onReady(function(){
                var airportds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getAllAirports'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root',
                        totalProperty: 'totalProperty',
                        id: 'post_id'
                    }, [{
                        name: 'airport_name'
                    }, {
                        name: 'airport_code'
                    }])
                });
                
                // Custom rendering Template
                var resultTpl = new Ext.XTemplate('<tpl for="."><div class="search-item">', '<h3><span>{airport_name}<br /></span>{airport_code}</h3>', '</div></tpl>');
                var airportFrom = new Ext.form.ComboBox({
					fieldLabel: '地点从',
					name: 'airport_code_from',
					anchor: '95%',
                    store: airportds,
                    displayField: 'title',
					hiddenName: 'airport_code_from',
                    typeAhead: false,
                    loadingText: '搜索中...',
                    width: 150,
                    pageSize: 10,
                    hideTrigger: true,
                    tpl: resultTpl,
                    editable: true,
                    //applyTo: 'search',
                    minChars: 2,
                    itemSelector: 'div.search-item',
                    onSelect: function(record){ // override default onSelect to do redirect
                        if (this.isExpanded()) {
                            this.collapse();
                        }
						airportFrom.setValue(record.data.airport_code);
						//当点击时关闭combobox
                        //window.location = String.format('http://extjs.com/forum/showthread.php?t={0}&p={1}', record.data.topicId, record.id);
                    }
                });
				var airportTo = new Ext.form.ComboBox({
					fieldLabel: '到',
					name: 'airport_code_to',
					anchor: '95%',
                    store: airportds,
                    displayField: 'title',
					hiddenName: 'airport_code_to',
                    typeAhead: false,
                    loadingText: '搜索中...',
                    width: 150,
                    pageSize: 10,
                    hideTrigger: true,
                    tpl: resultTpl,
                    editable: true,
                    //applyTo: 'search',
                    minChars: 2,
                    itemSelector: 'div.search-item',
                    onSelect: function(record){ // override default onSelect to do redirect
                        if (this.isExpanded()) {
                            this.collapse();
                        }
						airportTo.setValue(record.data.airport_code);
                    }
                });
                var airportsDateBegin = new Ext.form.DateField({
                    fieldLabel: '日期从',
                    name: 'airports_datebegin',
                    id: 'airports_datebegin',
                    format: 'Y-m-d', //格式化日期   
                    width: '80',
                    //disabledDays: [0,6],	//不让选择周六，周日   
                    //disabledDaysText: "周末要休息",   
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: true,
                    inputType: '2008-01-01',
                    anchor: '90%',
                    vtype: 'daterange',
                    endDateField: 'airports_dateend',
                    allowBlank: false,
                    listeners: {
                        select: function(field, e){
                            Ext.MessageBox.alert('提示', '提交成功');
                        }
                    }//,
                    //onTriggerClick:function(){Ext.MessageBox.alert('提示', '提交成功');}
                    //value:'1975-01-01'
                    //maxValue:'1925-01-01'
                });
                var airportsDateEnd = new Ext.form.DateField({
                    fieldLabel: '到',
                    name: 'airports_dateend',
                    id: 'airports_dateend',
                    format: 'Y-m-d', //格式化日期   
                    width: '80',
                    //disabledDays: [0,6],	//不让选择周六，周日   
                    //disabledDaysText: "周末要休息",   
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: true,
                    inputType: '2008-01-01',
                    anchor: '90%',
                    vtype: 'daterange',
                    startDateField: 'airports_datebegin',
                    allowBlank: false,
                    listeners: {
                        select: function(field, e){
                            Ext.MessageBox.alert('提示', '提交成功');
                        }
                    }//,
                    //onTriggerClick:function(){Ext.MessageBox.alert('提示', '提交成功');}
                    //value:'1975-01-01'
                    //maxValue:'1925-01-01'
                });
                var searchButton = new Ext.Button({
                    text: '生成报表',
                    handler: reportByAirports
                });
                var reportAirportsFormPanel = new Ext.form.FormPanel({
                    baseCls: 'x-plain',
                    labelWidth: 45,
                    width: '750',
                    //url: '/reports/dailySellReport',
                    //defaultType: 'textfield',
                    items: [{
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .20,
                            layout: 'form',
                            border: false,
                            items: [airportFrom]
                        },{
                            columnWidth: .20,
                            layout: 'form',
                            border: false,
                            items: [airportTo]
                        }, {
                            columnWidth: .20,
                            layout: 'form',
                            border: false,
                            items: [airportsDateBegin]
                        }, {
                            columnWidth: .20,
                            layout: 'form',
                            border: false,
                            items: [airportsDateEnd]
                        }, {
                            columnWidth: .10,
                            layout: 'form',
                            border: false,
                            items: [searchButton]
                        }]
                    }]
                });
                reportAirportsFormPanel.render('report_airways_form_div');
                function reportByAirports(){
                    if (reportAirportsFormPanel.form.isValid()) {
						//Ext.MessageBox.alert('Fuck',reportAirportsFormPanel.form.getValues(true));
                        Ext.Ajax.request({
                            url: '/reports/reportByAirports',
                            params: reportAirportsFormPanel.form.getValues(true),
                            method: 'GET',
                            success: function(result, request){
                                Ext.MessageBox.alert('报表提示', result.responseText);
                            },
                            failure: function(result, request){
                                Ext.MessageBox.alert('Failed', 'Not be found!');
                            }
                        });
                    }
                }
            });
        </script>
    </body>
</html>
